var playerInfo:PlayerObject;
var playerTower:Tower;
var oppPlayer:PlayerObject;
var oppTower:Tower;
var blockMaker:InstantiateBlocks;
var ui: UIHandler;

private var randomGen:Random=new Random();



//slot Array order PlayerNum:PlayerSlot:AbilityName:EgoDrain:Effect:Power:Duration:Type
function ExecuteMove(inButton:String)
{
	
	if(inButton==""){
		ui.ShowMessage("Player " +playerInfo.teamNum + " didn't select a move!",5);
	}
	else{
		var slotNum=findSlot(inButton);
		if (slotNum==0){
			chargeCheck=ui.GetChargeNum(playerInfo.teamNum,inButton);
			if(chargeCheck==2){
				blockMaker.MakeBlock(playerTower,inButton);
				ui.LoseCharge(playerInfo.teamNum,inButton);
				ui.LoseCharge(playerInfo.teamNum,inButton);
				ui.ShowMessage("Player " +playerInfo.teamNum + " created a " + inButton + " block!",3);
			}
			else{
				ui.ShowMessage("Player " +playerInfo.teamNum + " didn't have enough charge to create the Block!",3);
			}
		}
		else{	
			
			var curSlot=playerInfo.slots[slotNum-1];
			//Debug.Log(curSlot);
			//Debug.Log(curSlot[4]);
			playerInfo.DecreaseEgo(parseInt(curSlot[3]));
			var attackName=curSlot[2];
			var attackEffect=curSlot[4];
			
				
			var attackPower=parseInt(curSlot[5]);
			if(oppTower.attkCounter==50){
				attackPower=parseInt(attackPower/2);
				oppTower.setAttackCounter(0);
			}
			var effectDuration=parseInt(curSlot[6]);
			var attackType=curSlot[7];
			ui.AddCharge(playerInfo.teamNum,attackType);
			
			if (attackEffect=="Normal Attack" && attackType != "Logic")
			{
				oppTower.DamageTopBlock(attackPower);
				ui.ShowMessage("Player " + playerInfo.teamNum + " did " + attackPower 
					+ " damage to the opponent's tower with "+ attackName + "!", 3);
			}
			else if (attackEffect=="Ego Vampire")
			{
				oppPlayer.DecreaseEgo(attackPower);
				playerInfo.AddEgo(attackPower);
				ui.ShowMessage("Player " + playerInfo.teamNum + "stole " + attackPower
					+ " Ego with " +attackName +"!", 3);
			}
			
			else if (attackEffect=="Ego Burn")
			{
				oppPlayer.DecreaseEgo(attackPower);
				ui.ShowMessage("Player " + playerInfo.teamNum + "burned " + attackPower
					+ " Ego with " +attackName +"!", 3);
			}
			
			else if(attackEffect=="Ego Boost")
			{
				playerInfo.AddEgo(attackPower);
				ui.ShowMessage("Player " + playerInfo.teamNum + "gained " + attackPower
					+ " Ego with " +attackName +"!", 3);
			}
			else if(attackEffect=="Charge Boost"){
				var typeArr=["Passion","Logic","Deception","Ethics"];
				var chosenSlot= parseInt((randomGen.value*100)%4);
				ui.AddCharge(playerInfo.teamNum,typeArr[chosenSlot]);
				ui.ShowMessage("Player " + playerInfo.teamNum + "got a " + typeArr[chosenSlot]
					+ " Charge with " +attackName +"!", 3);
			}
			else if(attackEffect=="Sacrifice Attack"){
				playerTower.DamageTopBlock(10);
				oppTower.DamageTopBlock(attackPower);
				ui.ShowMessage("Player " +playerInfo.teamNum + " sacrificed height to do " + attackPower +
					" damage to the opposing Tower.",3);
			}
			else if(attackEffect=="Charge Boost"){
				var typeArray=["Passion","Logic","Deception","Ethics"];
				var choseSlot= parseInt((randomGen.value*100)%4);
				ui.LoseCharge(oppPlayer.teamNum,typeArr[chosenSlot]);
				ui.ShowMessage("Player " + playerInfo.teamNum + "destroyed a " + typeArray[choseSlot]
					+ " Charge with " +attackName +"!", 3);
			}
			else if(attackEffect=="Counter"){
				playerTower.setAttackCounter(1);
				ui.SendMessage("Player " + playerInfo.teamNum + " cast something on himself....",3);
			}
		}
	}
}

function findSlot(inButton:String){
	if(inButton=="11" || inButton=="21"){
		return 1;
	}
	else if(inButton=="12" || inButton=="22"){
		return 2;
	}
	else if(inButton=="13" || inButton=="23"){
		return 3;
	}
	else if(inButton=="14" || inButton=="24"){
		return 4;
	}
	else if(inButton=="15" || inButton=="25"){
		return 5;
	}
	else{
		return 0;
	}
}
	
	
	
	
	

	